home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / SelectLanguage / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  3KB  |  162 lines

  1. /*
  2.  
  3.   SelectLanguage
  4.   ==============
  5.  
  6.     The main purpose of this door is to get the user to pick a language/screen type
  7.  
  8. */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <dos/dos.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/dos_protos.h>
  15. #include <clib/alib_protos.h>
  16.  
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include <time.h>
  22.  
  23. #include <HBBS/ANSI_Codes.h>
  24. #include <HBBS/Defines.h>
  25. #include <HBBS/types.h>
  26. #include <HBBS/structures.h>
  27. #include <HBBS/hbbscommon_protos.h>
  28. #include <HBBS/hbbscommon_pragmas.h>
  29. #include <HBBS/Hbbsnode_protos.h>
  30. #include <HBBS/Hbbsnode_pragmas.h>
  31. #include <HBBS/release.h>
  32. char *versionstr="$VER: SelectLanguage "RELEASE_STR;
  33.  
  34. struct Library *HBBSCommonBase=NULL;
  35. struct Library *HBBSNodeBase=NULL;
  36.  
  37. struct BBSGlobalData *BBSGlobal=NULL;
  38. struct NodeData *N_ND=NULL;
  39. int    N_NodeNum=-1;
  40. char   outstr[1024]; // temp string for displaying text..
  41.  
  42. int    gargc;
  43. char   **gargv;
  44.  
  45.  
  46. #ifdef __SASC
  47. int CXBRK(void) { return(0); }
  48. int _CXBRK(void) { return(0); }
  49. void chkabort(void) {}
  50. #endif
  51.  
  52.  
  53. static VOID cleanup(ULONG num)
  54. {
  55.   if (HBBSNodeBase)
  56.   {
  57.     HBBS_CleanUpDoor();
  58.     CloseLibrary (HBBSNodeBase);
  59.   }
  60.  
  61.   if (HBBSCommonBase)
  62.   {
  63.     HBBS_CleanUpCommon();
  64.     CloseLibrary (HBBSCommonBase);
  65.   }
  66.  
  67.   if (num) printf("Door Error = %d\n",num);
  68.  
  69.   exit(0);
  70. }
  71.  
  72. static VOID init(char *name)
  73. {
  74.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  75.   {
  76.     cleanup(1);
  77.   }
  78.  
  79.   if (!(HBBS_InitCommon()))
  80.   {
  81.     cleanup(2);
  82.   }
  83.  
  84.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  85.   {
  86.     cleanup(3);
  87.   }
  88.  
  89.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  90.   {
  91.     cleanup(4);
  92.   }
  93.   SetProgramName(name);
  94. }
  95.  
  96. void DoorMain( void )
  97. {
  98.   LONG loop;
  99.   struct Node *node;
  100.   BOOL Done=FALSE;
  101.   // set to default if before a possible error occures
  102.  
  103.   N_ND->User.CallData.Language=1;
  104.   N_ND->User.NormalData.Language=1;
  105.  
  106.   DOOR_WriteText(ANSI_RESET);
  107.  
  108.   for (loop=1,node = BBSGlobal->LanguageName->lh_Head ; node->ln_Succ ; node=node->ln_Succ,loop++)
  109.   {
  110.     sprintf(outstr,ANSI_FG_WHITE"%d) "ANSI_FG_CYAN"%s\r\n"ANSI_RESET,loop,node->ln_Name);
  111.     DOOR_WriteText(outstr);
  112.   }
  113.  
  114.   do
  115.   {
  116.     DOOR_WriteText(ANSI_FG_YELLOW "Select A Language/Screen Type "ANSI_FG_BLUE": "ANSI_FG_WHITE);
  117.  
  118.     strcpy(N_ND->CharsAllowed,"0123456789");
  119.                                                      // more than 99 langauges ?  I don't think so.. :-)
  120.     DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_USECHARS|GL_IMMEDIATE,'\0',BBSGlobal->Languages > 9 ? 2 : 1,0,NULL);
  121.  
  122.     if (N_ND->OnlineStatus==OS_ONLINE)
  123.     {
  124.       if (sscanf(N_ND->CurrentLine,"%ld",&loop))
  125.       {
  126.         if (loop>=1 && loop<=BBSGlobal->Languages)
  127.         {
  128.           N_ND->User.CallData.Language=loop;
  129.           N_ND->User.NormalData.Language=loop;
  130.           Done=TRUE;
  131.         }
  132.       }
  133.     }
  134.     else
  135.     {
  136.       Done=TRUE;
  137.     }
  138.   } while (!Done);
  139. }
  140.  
  141. int main(int argc,char **argv)
  142. {
  143.   gargc=argc;
  144.   gargv=argv;
  145.  
  146.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  147.   {
  148.     printf("Invalid/No Paramaters for door!\n");
  149.     exit (20);
  150.   }
  151.   init("<doorname>");
  152.  
  153.   if (BBSGlobal=HBBS_GimmeBBS())
  154.   {
  155.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  156.     {
  157.       DoorMain();
  158.     }
  159.   }
  160.   cleanup(0);
  161. }
  162.